# import re
# import pandas as pd
#
# # 评论数据处理
# data = pd.read_csv(r'D:/Scrapy_data/merged_data_comment.csv', encoding='gbk', header=None)
# pattern_1 = r'\{[^{}]*\}'
# pattern_2 = r'([^:]+):([^,]+),?'
# empty_df = pd.DataFrame(columns=range(11))
# for j in data.itertuples():
#     a = j[1]
#     comments = re.findall(pattern_1, j[2])
#     for comment in comments:
#         print(comment)
#         matches = re.findall(pattern_2, comment)
#         comment_2 = []
#         for match in matches:
#             value = match[1].strip()
#             comment_2.append(value)
#
#         # 将comment_2列表转换为Series对象
#         series = pd.Series(comment_2)
#
#         # 将Series添加到DataFrame中
#         empty_df.loc[len(empty_df)] = [a] + list(series)
#
# empty_df.to_csv('D:/Scrapy_data/comment.csv', index=False)
#
# import re
# import pandas as pd
#
# data2 = pd.read_csv(r'D:/Scrapy_data/16888/car_car.csv', encoding='gbk', header=None)
# pattern_3 = r'[^,]+'
# pattern_4 = r'(.*?):\s*(.*?)$'
# empty_df = pd.DataFrame(columns=['a', 'error'])
# for j in data2.itertuples():
#     a = j[1]
#     error = []
#     msg = re.findall(pattern_3, j[2])
#     for i in msg:
#         matches = re.findall(pattern_4, i)
#         for match in matches:
#             erroemsg = {}
#             before_data, after_data = match
#             try:
#                 erroemsg[before_data.strip()] = int(after_data)
#                 error.append(erroemsg)
#             except Exception as e:
#                 # 发生异常时的处理逻辑
#                 erroemsg[before_data.strip()] = after_data = 'NULL'
#                 error.append(erroemsg)
#
#     empty_df = empty_df.append({'a': a, 'error': error}, ignore_index=True)
# empty_df.to_csv('D:/Scrapy_data/car_ca8r.csv', index=False)
#
#
#
#
#
#
#
#
#
#
#
#
